from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import  ChatOpenAI
from langchain_core.output_parsers import StrOutputParser

prompt_template = ChatPromptTemplate.from_template("你是一个IT助手,回答下面这个问题{question}")

#模型
mode = ChatOpenAI(model_name="qwen-plus",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key="sk-4f1498f1c0314ba79ea2919bd7a02c4d",
    temperature=0.7
)

#构建解析器
parser = StrOutputParser()

#构建链
chain = prompt_template | mode | parser

result = chain.invoke({"question":"如何学习Java"})

print(result)